home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Development
/
Source
/
Little C Source
/
Ex1.c
next >
Wrap
C/C++ Source or Header
|
1993-10-04
|
875b
|
50 lines
/* C Interpreter Demonstration Program
This program demonstrates all features
of C that are recognized by this C interpreter.
*/
int i, j; /* global vars */
char ch;
main()
{
int i, j; /* local vars */
puts("C Demo Program.");
print_alpha();
do {
puts("enter a number (0 to quit): ");
i = getnum();
if(i < 0 ) {
puts("numbers must be positive, try again");
}
else {
for(j = 0; j < i; j=j+1) {
print(j);
print("summed is");
print(sum(j));
puts("");
}
}
} while(i!=0);
}
/* Sum the values between 0 and num. */
sum(int num)
{
int running_sum;
running_sum = 0;
while(num) {
running_sum = running_sum + num;
num = num - 1;
}
return running_sum;
}
/* Print the alphabet. */
print_alpha()
{
for(ch = 'A'; ch<='Z'; ch = ch + 1) {
putch(ch);
}
puts("");
}